package com.lifo.good.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lifo.good.bean.model.HfCategory;
import com.lifo.good.bean.model.HfGoods;
import com.lifo.good.service.SearchGoodCategoryService;
import com.lifo.good.service.SearchGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author why
 * @date 2018/4/19 0019
 */
@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {
    final Long SKIRTS_CATEGORYID = 100006L;
    final Long SHIRT_CATEGORYID = 100001L;

    @Autowired
    private SearchGoodsService searchGoodsService;

    @Autowired
    private SearchGoodCategoryService searchGoodCategoryService;

    /**
     * 新上架商品
     * @param model
     * @return
     */
    @RequestMapping(value = "/newGoods", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public String newGoods(Model model) {


        //新品推荐
        PageInfo<HfGoods> page = searchGoodsService.searchHfGoodsByPage(0, 6);
        String json = JSON.toJSONString(page);

        return json;
    }

    /**
     * 一楼商品
     * @param model
     * @return
     */
    @RequestMapping(value = "/oneFloor", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public String oneFloor(Model model) {


        //裙装
        PageInfo<HfGoods> pageInfo = searchGoodsService.searchHfGoodsByCategory(SKIRTS_CATEGORYID, 1, 15);
        String json = JSON.toJSONString(pageInfo);
        return json;
    }

    /**
     * 二楼商品
     * @param model
     * @return
     */
    @RequestMapping(value = "/twoFloor", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public String twoFloor(Model model) {

        //衬衣
        PageInfo<HfGoods> pageInfo = searchGoodsService.searchHfGoodsByCategory(SHIRT_CATEGORYID, 1, 15);

        String json = JSON.toJSONString(pageInfo);
        return json;
    }

    /**
     * 查询一级目录
     * @param model
     * @return
     */
    @RequestMapping(value = "/oneLevel", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public String oneLevel(Model model) {

        //一级目录
        List<HfCategory> oneLevel = searchGoodCategoryService.searchHfCatgegoryOneLevel();
        String json = JSON.toJSONString(oneLevel);
        return json;
    }


    /**
     * 查询二级目录
     */
    @RequestMapping(value = "/getTwoLevel", produces = "application/json;charset=UTF-8" )
    public String getTwoLevel(  HfCategory vo)  {
        List<HfCategory> hfCategories = searchGoodCategoryService.searchHfCategoryTwoLevelByOneLevel(vo.getFirstLevel());
        String json= JSON.toJSONString(hfCategories);
        log.info("=====>{}",json);
        return json;
    }

}
